package com.hh.core.log;

import java.util.TimerTask;

import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;

import com.hh.admin.entity.SysLoginLog;
import com.hh.admin.entity.SysOperationLog;
import com.hh.admin.mapper.SysLoginLogMapper;
import com.hh.admin.mapper.SysOperationLogMapper;
import com.hh.core.common.SpringContextHolder;

public class LogTaskFactory {

	private static final Log log = LogFactory.get();

	private static SysLoginLogMapper loginLogMapper = SpringContextHolder
			.getBean(SysLoginLogMapper.class);

	private static SysOperationLogMapper operationLogMapper = SpringContextHolder
			.getBean(SysOperationLogMapper.class);

	/**
	 * 
	 * @Title: operationLog
	 * @Description: 操作日志保存 线程
	 * @param @param type
	 * @param @param name
	 * @param @param userId
	 * @param @param className
	 * @param @param method
	 * @param @param content
	 * @param @return 设定文件
	 * @return TimerTask 返回类型
	 * @author hxn
	 * @date 2018年2月13日 上午9:44:49
	 * @throws
	 */
	public static TimerTask operationLog(final Integer type, final String name,
			final Long userId, final String className, final String method,
			final String content) {
		return new TimerTask() {
			@Override
			public void run() {
				SysOperationLog operationLog = new SysOperationLog(type, name,
						userId, className, method, content);
				try {
					operationLogMapper.insert(operationLog);
				} catch (Exception e) {
					e.printStackTrace();
					log.error(e,"保存操作日志错误");
				}

			}
		};
	}

	public static TimerTask loginLog(final Integer type, final Long userId,
			final String ip, final String userAccount) {
		return new TimerTask() {
			@Override
			public void run() {
				SysLoginLog loginLog = new SysLoginLog(type, userId, ip,
						userAccount);
				try {
					loginLogMapper.insert(loginLog);
				} catch (Exception e) {
					log.error(e,"保存登录日志错误");
				}

			}
		};
	}
}
